# Create your views here.
import logging
import datetime
from django.http import HttpResponse
from models import *

def out_user(request):
    now=datetime.now()
    span = timedelta(seconds=60*15)
    spot=now-span
    
    q_out_onlines=Online.all().filter('updated_on <', spot)
    
    out_onlines=q_out_onlines.fetch(100)
    
    cnt=0
    for o in out_onlines:
        cnt=cnt+1
        if o.user is None:
            logging.log(logging.INFO, "out_line guest from %s"%o.ip)
            
        else:
            logging.log(logging.INFO,"out_line user %s from %s"%(o.user.username,o.ip))
        
        o.delete()   
    msg= "***    out_line %d users at %s    ***"%(cnt,str(now))
    logging.log(logging.INFO, msg)
    
    return HttpResponse(msg)
            
    